using MicroMsg.Common.Utils;
using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Diagnostics;
using System.Linq;
using System.Linq.Expressions;
namespace MicroMsg.Storage
{
	public class StorageTable<T, PKey> : IStorageLogin, IStorageFlush where T : StorageItem
	{
		private const string TAG = "StorageTable";
		public const int ON_DB_ADD = 0;
		public const int ON_DB_DEL = 1;
		public const int ON_DB_MOD = 2;
		private bool bInit;
		protected Table<T> tableR;
		private StorageMapping mapping;
		private Expression<Func<T, PKey>> PrimaryKeyExp;
		private Func<T, PKey> getKey;
		private StorageSynchro<T, PKey> storageSynchro_0;
		public StorageTable()
		{
			StorageBasic.registerLoginNotify(this);
			this.mapping = StorageDB.default_mapping;
		}
		public StorageTable(Expression<Func<T, PKey>> keySelector) : this()
		{
			this.setKeySelector(keySelector);
		}
		public void setKeySelector(Expression<Func<T, PKey>> keySelector)
		{
			if (keySelector == null)
			{
				return;
			}
			ParameterExpression parameterExpression = keySelector.get_Parameters().get_Item(0);
			MemberExpression memberExpression = (MemberExpression)keySelector.get_Body();
			if (parameterExpression != null && memberExpression != null)
			{
				this.PrimaryKeyExp = keySelector;
				this.getKey = keySelector.Compile();
				return;
			}
		}
		public void setMapping(StorageMapping storageMapping_0)
		{
			this.mapping = storageMapping_0;
		}
		protected virtual bool init()
		{
			if (!this.mapping.isAvailable())
			{
				return false;
			}
			if (this.bInit)
			{
				DebugEx.debugBreak();
			}
			this.bInit = true;
			DataContext dB = this.mapping.getDB();
			this.tableR = dB.GetTable<T>();
			return true;
		}
		protected virtual void uninit()
		{
			this.onFlush();
			this.tableR = null;
			this.bInit = false;
		}
		public bool isReady()
		{
			if (!this.bInit)
			{
				this.init();
			}
			return this.bInit && this.mapping.isAvailable();
		}
		public virtual void onLogin(string userName)
		{
		}
		public virtual void onLogout()
		{
			this.uninit();
		}
		public void debugBreak()
		{
			if (Debugger.get_IsAttached())
			{
				Debugger.Break();
			}
		}
		public virtual bool check(T item)
		{
			return item != null && (this.getKey == null || typeof(PKey) != typeof(string) || this.valid(this.getKey.Invoke(item)));
		}
		protected bool valid(object param)
		{
			return param != null && (!(param is string) || !string.IsNullOrEmpty(param as string));
		}
		protected void clearException(DataContext dataContext_0)
		{
			ChangeSet changeSet = dataContext_0.GetChangeSet();
			using (IEnumerator<object> enumerator = changeSet.get_Inserts().GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					object current = enumerator.get_Current();
					dataContext_0.GetTable(current.GetType()).DeleteOnSubmit(current);
				}
			}
			using (IEnumerator<object> enumerator2 = changeSet.get_Deletes().GetEnumerator())
			{
				while (enumerator2.MoveNext())
				{
					object current2 = enumerator2.get_Current();
					dataContext_0.GetTable(current2.GetType()).InsertOnSubmit(current2);
				}
			}
		}
		protected int method_0(Expression<Func<T, bool>> predicate = null)
		{
			if (!this.isReady())
			{
				return 0;
			}
			if (predicate == null)
			{
				return Queryable.Count<T>(this.tableR);
			}
			return Queryable.Count<T>(Queryable.Where<T>(this.tableR, predicate));
		}
		public bool IsEmpty()
		{
			return this.isReady() && !Queryable.Any<T>(this.tableR);
		}
		public int count()
		{
			return this.method_0(null);
		}
		private Expression<Func<T, bool>> buildQueryByKeyExp(PKey keyValue)
		{
			ParameterExpression parameterExpression = this.PrimaryKeyExp.get_Parameters().get_Item(0);
			MemberExpression memberExpression = (MemberExpression)this.PrimaryKeyExp.get_Body();
			ConstantExpression constantExpression = Expression.Constant(keyValue, typeof(PKey));
			BinaryExpression binaryExpression = Expression.Equal(memberExpression, constantExpression);
			return Expression.Lambda<Func<T, bool>>(binaryExpression, new ParameterExpression[]
			{
				parameterExpression
			});
		}
		public T method_1(PKey keySearch)
		{
			if (this.valid(keySearch) && this.isReady() && this.PrimaryKeyExp != null)
			{
				try
				{
					Expression<Func<T, bool>> expression = this.buildQueryByKeyExp(keySearch);
					return Queryable.FirstOrDefault<T>(Queryable.Where<T>(this.tableR, expression));
				}
				catch (Exception ex)
				{
					Log.smethod_1("storage", "StorageTable get exception" + ex);
					this.debugBreak();
				}
				return default(T);
			}
			return default(T);
		}
		protected T method_2(Expression<Func<T, bool>> predicate)
		{
			if (this.isReady() && predicate != null)
			{
				try
				{
					return Queryable.FirstOrDefault<T>(Queryable.Where<T>(this.tableR, predicate));
				}
				catch (Exception ex)
				{
					Log.smethod_1("storage", "StorageTable get exception" + ex);
					this.debugBreak();
				}
				return default(T);
			}
			return default(T);
		}
		protected List<T> search(Expression<Func<T, bool>> predicate = null, int start = -1, int int_0 = -1)
		{
			if (!this.isReady())
			{
				return null;
			}
			try
			{
				if (predicate == null)
				{
					List<T> result;
					if (start < 0)
					{
						result = Enumerable.ToList<T>(this.tableR);
						return result;
					}
					result = Enumerable.ToList<T>(Queryable.Take<T>(Queryable.Skip<T>(this.tableR, start), int_0));
					return result;
				}
				else
				{
					List<T> result;
					if (start < 0)
					{
						result = Enumerable.ToList<T>(Queryable.Where<T>(this.tableR, predicate));
						return result;
					}
					result = Enumerable.ToList<T>(Queryable.Take<T>(Queryable.Skip<T>(Queryable.Where<T>(this.tableR, predicate), start), int_0));
					return result;
				}
			}
			catch (Exception ex)
			{
				Log.smethod_1("storage", "StorageTable get exception" + ex);
				this.debugBreak();
			}
			return null;
		}
		public List<T> getList()
		{
			return this.search(null, -1, 0);
		}
		public List<T> getList(int start, int int_0)
		{
			if (start >= 0 && int_0 > 0)
			{
				return this.search(null, start, int_0);
			}
			return null;
		}
		protected List<T> getList(Expression<Func<T, bool>> predicate)
		{
			if (predicate == null)
			{
				return null;
			}
			return this.search(predicate, -1, -1);
		}
		protected List<T> getList(Expression<Func<T, bool>> predicate, int start, int int_0)
		{
			if (predicate != null && start >= 0 && int_0 > 0)
			{
				return this.search(predicate, start, int_0);
			}
			return null;
		}
		protected List<T> getOrderList<TKey>(Expression<Func<T, TKey>> keySelector, int start, int int_0)
		{
			if (!this.isReady())
			{
				return null;
			}
			try
			{
				return Enumerable.ToList<T>(Queryable.Take<T>(Queryable.Skip<T>(Queryable.OrderBy<T, TKey>(this.tableR, keySelector), start), int_0));
			}
			catch (Exception ex)
			{
				Log.smethod_1("StorageTable", "StorageTable getOrderList exception" + ex);
				this.debugBreak();
			}
			return null;
		}
		public bool method_3(T item)
		{
			if (this.check(item) && this.isReady())
			{
				using (DataContext dataContext = this.mapping.newDB())
				{
					Table<T> table = dataContext.GetTable<T>();
					try
					{
						table.InsertOnSubmit(item);
						dataContext.SubmitChanges();
						this.notify(0, item);
						return true;
					}
					catch (Exception ex)
					{
						this.clearException(dataContext);
						Log.smethod_1("storage", "StorageTable exception" + ex);
						this.debugBreak();
					}
				}
				return false;
			}
			return false;
		}
		public bool addList(List<T> itemList)
		{
			if (itemList != null && itemList.get_Count() > 0 && this.isReady())
			{
				using (DataContext dataContext = this.mapping.newDB())
				{
					Table<T> table = dataContext.GetTable<T>();
					try
					{
						table.InsertAllOnSubmit<T>(itemList);
						dataContext.SubmitChanges();
						using (List<T>.Enumerator enumerator = itemList.GetEnumerator())
						{
							while (enumerator.MoveNext())
							{
								T current = enumerator.get_Current();
								this.notify(0, current);
							}
						}
						return true;
					}
					catch (Exception ex)
					{
						this.clearException(dataContext);
						Log.smethod_1("storage", "StorageTable exception" + ex);
						this.debugBreak();
					}
				}
				return false;
			}
			return false;
		}
		public bool method_4(T item)
		{
			if (!this.check(item) || !this.isReady())
			{
				return false;
			}
			if (!Queryable.Any<T>(this.tableR))
			{
				return true;
			}
			using (DataContext dataContext = this.mapping.newDB())
			{
				Table<T> table = dataContext.GetTable<T>();
				try
				{
					table.Attach(item);
					dataContext.Refresh(0, item);
					table.DeleteOnSubmit(item);
					dataContext.SubmitChanges();
					this.notify(1, item);
					return true;
				}
				catch (Exception ex)
				{
					this.clearException(dataContext);
					Log.smethod_1("storage", "StorageTable exception" + ex);
					this.debugBreak();
				}
			}
			return false;
		}
		public bool method_5(PKey gparam_0)
		{
			if (!this.isReady() || !this.valid(gparam_0) || this.PrimaryKeyExp == null)
			{
				return false;
			}
			if (!Queryable.Any<T>(this.tableR))
			{
				return true;
			}
			Expression<Func<T, bool>> predicate = this.buildQueryByKeyExp(gparam_0);
			return this.method_6(predicate);
		}
		protected bool method_6(Expression<Func<T, bool>> predicate)
		{
			if (predicate == null || !this.isReady())
			{
				return false;
			}
			if (!Queryable.Any<T>(this.tableR))
			{
				return true;
			}
			using (DataContext dataContext = this.mapping.newDB())
			{
				Table<T> table = dataContext.GetTable<T>();
				try
				{
					List<T> list = Enumerable.ToList<T>(Queryable.Where<T>(table, predicate));
					bool result;
					if (Enumerable.Count<T>(list) <= 0)
					{
						result = true;
						return result;
					}
					table.DeleteAllOnSubmit<T>(list);
					dataContext.SubmitChanges();
					using (List<T>.Enumerator enumerator = list.GetEnumerator())
					{
						while (enumerator.MoveNext())
						{
							T current = enumerator.get_Current();
							this.notify(1, current);
						}
					}
					result = true;
					return result;
				}
				catch (Exception ex)
				{
					this.clearException(dataContext);
					Log.smethod_1("storage", "StorageTable get exception" + ex);
					this.debugBreak();
				}
			}
			return false;
		}
		public bool delList(List<T> itemList)
		{
			if (itemList == null || itemList.get_Count() <= 0 || !this.isReady())
			{
				return false;
			}
			if (!Queryable.Any<T>(this.tableR))
			{
				return true;
			}
			using (DataContext dataContext = this.mapping.newDB())
			{
				Table<T> table = dataContext.GetTable<T>();
				try
				{
					using (List<T>.Enumerator enumerator = itemList.GetEnumerator())
					{
						while (enumerator.MoveNext())
						{
							T current = enumerator.get_Current();
							table.Attach(current);
							dataContext.Refresh(0, current);
						}
					}
					table.DeleteAllOnSubmit<T>(itemList);
					dataContext.SubmitChanges();
					using (List<T>.Enumerator enumerator2 = itemList.GetEnumerator())
					{
						while (enumerator2.MoveNext())
						{
							T current2 = enumerator2.get_Current();
							this.notify(1, current2);
						}
					}
					return true;
				}
				catch (Exception ex)
				{
					this.clearException(dataContext);
					Log.smethod_1("storage", "StorageTable get exception" + ex);
					this.debugBreak();
				}
			}
			return false;
		}
		public virtual bool delTop(int int_0)
		{
			if (!this.isReady())
			{
				return false;
			}
			if (!Queryable.Any<T>(this.tableR))
			{
				return true;
			}
			using (DataContext dataContext = this.mapping.newDB())
			{
				Table<T> table = dataContext.GetTable<T>();
				try
				{
					List<T> list = Enumerable.ToList<T>(Queryable.Take<T>(table, int_0));
					bool result;
					if (list.get_Count() <= 0)
					{
						result = true;
						return result;
					}
					table.DeleteAllOnSubmit<T>(list);
					dataContext.SubmitChanges();
					using (List<T>.Enumerator enumerator = list.GetEnumerator())
					{
						while (enumerator.MoveNext())
						{
							T current = enumerator.get_Current();
							this.notify(1, current);
						}
					}
					result = true;
					return result;
				}
				catch (Exception ex)
				{
					this.clearException(dataContext);
					Log.smethod_1("storage", "StorageTable delTop " + ex);
					this.debugBreak();
				}
			}
			return false;
		}
		public void clearAll()
		{
			this.method_6((T m) => true);
		}
		public bool modify(T item)
		{
			if (this.check(item) && this.isReady())
			{
				using (DataContext dataContext = this.mapping.newDB())
				{
					try
					{
						Table<T> table = dataContext.GetTable<T>();
						table.Attach(item);
						dataContext.Refresh(0, item);
						dataContext.SubmitChanges();
						this.notify(2, item);
						return true;
					}
					catch (Exception ex)
					{
						Log.smethod_1("storage", "StorageTable modify exception" + ex);
						this.debugBreak();
					}
				}
				return false;
			}
			return false;
		}
		public bool update(T item)
		{
			if (!this.check(item) || !this.isReady() || this.PrimaryKeyExp == null)
			{
				return false;
			}
			PKey pKey = this.getKey.Invoke(item);
			if (!this.valid(pKey))
			{
				return false;
			}
			Expression<Func<T, bool>> expression_ = this.buildQueryByKeyExp(pKey);
			return this.update(item, expression_);
		}
		protected bool update(T item, Expression<Func<T, bool>> expression_0)
		{
			if (expression_0 != null && this.check(item) && this.isReady())
			{
				using (DataContext dataContext = this.mapping.newDB())
				{
					Table<T> table = dataContext.GetTable<T>();
					try
					{
						T t = Queryable.FirstOrDefault<T>(Queryable.Where<T>(table, expression_0));
						if (t != null)
						{
							if (t != item)
							{
								t.merge(item);
								t.modify = item.modify;
								item.modify = 0L;
							}
							this.notify(2, t);
						}
						else
						{
							table.InsertOnSubmit(item);
							this.notify(0, item);
						}
						dataContext.SubmitChanges();
					}
					catch (Exception ex)
					{
						Log.smethod_1("storage", "StorageTable update1 exception " + ex);
						this.clearException(dataContext);
						this.debugBreak();
						return false;
					}
				}
				return true;
			}
			return false;
		}
		private List<T> queryByLinq<TKey>(Table<T> table, List<TKey> keyList, Expression<Func<T, TKey>> keySelectorExp)
		{
			ParameterExpression parameterExpression = Expression.Parameter(typeof(T), "item");
			MethodCallExpression methodCallExpression = Expression.Call(Expression.Constant(keyList, typeof(List<TKey>)), "Contains", null, new Expression[]
			{
				Expression.Invoke(keySelectorExp, new Expression[]
				{
					parameterExpression
				})
			});
			Expression<Func<T, bool>> expression = Expression.Lambda<Func<T, bool>>(methodCallExpression, new ParameterExpression[]
			{
				parameterExpression
			});
			return Enumerable.ToList<T>(Queryable.Where<T>(table, expression));
		}
		private List<T> queryByDict<TKey>(Table<T> table, List<TKey> keyList, Expression<Func<T, TKey>> keySelectorExp)
		{
			Func<IGrouping<TKey, T>, bool> func = null;
			Func<IGrouping<TKey, T>, TKey> func2 = null;
			Func<IGrouping<TKey, T>, T> func3 = null;
			Func<T, TKey> func4 = keySelectorExp.Compile();
			try
			{
				IEnumerable<IGrouping<TKey, T>> arg_25_0 = Enumerable.GroupBy<T, TKey>(table, func4);
				if (func == null)
				{
					func = ((IGrouping<TKey, T> igrouping_0) => igrouping_0.get_Key() != null);
				}
				IEnumerable<IGrouping<TKey, T>> arg_4C_0 = Enumerable.Where<IGrouping<TKey, T>>(arg_25_0, func);
				if (func2 == null)
				{
					func2 = ((IGrouping<TKey, T> igrouping_0) => igrouping_0.get_Key());
				}
				Func<IGrouping<TKey, T>, TKey> arg_4C_1 = func2;
				if (func3 == null)
				{
					func3 = ((IGrouping<TKey, T> igrouping_0) => Enumerable.First<T>(igrouping_0));
				}
				Dictionary<TKey, T> dictionary = Enumerable.ToDictionary<IGrouping<TKey, T>, TKey, T>(arg_4C_0, arg_4C_1, func3);
				List<T> list = new List<T>();
				using (List<TKey>.Enumerator enumerator = keyList.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						TKey current = enumerator.get_Current();
						if (dictionary.ContainsKey(current))
						{
							list.Add(dictionary.get_Item(current));
						}
					}
				}
				return list;
			}
			catch (Exception ex)
			{
				Log.smethod_1("storage", "StorageTable queryByDict exception" + ex);
				this.debugBreak();
			}
			return null;
		}
		private List<T> queryOptimize<TKey>(Table<T> table, List<TKey> keyList, Expression<Func<T, TKey>> keySelectorExp)
		{
			if (Queryable.Count<T>(this.tableR) > 2000)
			{
				return this.queryByLinq<TKey>(table, keyList, keySelectorExp);
			}
			if (Enumerable.Count<TKey>(keyList) < 20)
			{
				return this.queryByLinq<TKey>(table, keyList, keySelectorExp);
			}
			return this.queryByDict<TKey>(table, keyList, keySelectorExp);
		}
		protected bool updateList<TKey>(List<T> itemList, Expression<Func<T, TKey>> keySelectorExp)
		{
			Func<IGrouping<TKey, T>, bool> func = null;
			Func<IGrouping<TKey, T>, TKey> func2 = null;
			Func<KeyValuePair<TKey, IGrouping<TKey, T>>, TKey> func3 = null;
			Func<KeyValuePair<TKey, IGrouping<TKey, T>>, T> func4 = null;
			if (keySelectorExp != null && itemList != null && itemList.get_Count() > 0 && this.isReady())
			{
				using (DataContext dataContext = this.mapping.newDB())
				{
					try
					{
						Table<T> table = dataContext.GetTable<T>();
						Func<T, TKey> func5 = keySelectorExp.Compile();
						DebugEx.getTimeSpan(0L);
						IEnumerable<IGrouping<TKey, T>> arg_6A_0 = Enumerable.GroupBy<T, TKey>(itemList, func5);
						if (func == null)
						{
							func = ((IGrouping<TKey, T> igrouping_0) => igrouping_0.get_Key() != null);
						}
						IEnumerable<IGrouping<TKey, T>> arg_80_0 = Enumerable.Where<IGrouping<TKey, T>>(arg_6A_0, func);
						if (func2 == null)
						{
							func2 = ((IGrouping<TKey, T> igrouping_0) => igrouping_0.get_Key());
						}
						Dictionary<TKey, IGrouping<TKey, T>> dictionary = Enumerable.ToDictionary<IGrouping<TKey, T>, TKey>(arg_80_0, func2);
						IEnumerable<KeyValuePair<TKey, IGrouping<TKey, T>>> arg_9A_0 = dictionary;
						if (func3 == null)
						{
							func3 = ((KeyValuePair<TKey, IGrouping<TKey, T>> keyValuePair_0) => keyValuePair_0.get_Key());
						}
						List<TKey> keyList = Enumerable.ToList<TKey>(Enumerable.Select<KeyValuePair<TKey, IGrouping<TKey, T>>, TKey>(arg_9A_0, func3));
						List<T> list = this.queryOptimize<TKey>(table, keyList, keySelectorExp);
						using (List<T>.Enumerator enumerator = list.GetEnumerator())
						{
							while (enumerator.MoveNext())
							{
								T current = enumerator.get_Current();
								TKey tKey = func5.Invoke(current);
								if (dictionary.ContainsKey(tKey))
								{
									IGrouping<TKey, T> grouping = dictionary.get_Item(tKey);
									current.modify = 0L;
									using (IEnumerator<T> enumerator2 = grouping.GetEnumerator())
									{
										while (enumerator2.MoveNext())
										{
											T current2 = enumerator2.get_Current();
											current.merge(current2);
											current.modify |= current2.modify;
										}
									}
									dictionary.Remove(tKey);
									this.notify(2, current);
								}
							}
						}
						if (Enumerable.Count<KeyValuePair<TKey, IGrouping<TKey, T>>>(dictionary) > 0)
						{
							using (Dictionary<TKey, IGrouping<TKey, T>>.Enumerator enumerator3 = dictionary.GetEnumerator())
							{
								while (enumerator3.MoveNext())
								{
									KeyValuePair<TKey, IGrouping<TKey, T>> current3 = enumerator3.get_Current();
									IGrouping<TKey, T> value = current3.get_Value();
									T t = Enumerable.First<T>(value);
									if (Enumerable.Count<T>(value) > 1)
									{
										using (IEnumerator<T> enumerator4 = value.GetEnumerator())
										{
											while (enumerator4.MoveNext())
											{
												T current4 = enumerator4.get_Current();
												if (current4 != t)
												{
													t.merge(current4);
													t.modify |= current4.modify;
												}
											}
										}
									}
									this.notify(0, t);
								}
							}
							Table<T> arg_27A_0 = table;
							IEnumerable<KeyValuePair<TKey, IGrouping<TKey, T>>> arg_275_0 = dictionary;
							if (func4 == null)
							{
								func4 = ((KeyValuePair<TKey, IGrouping<TKey, T>> keyValuePair_0) => Enumerable.First<T>(keyValuePair_0.get_Value()));
							}
							arg_27A_0.InsertAllOnSubmit<T>(Enumerable.Select<KeyValuePair<TKey, IGrouping<TKey, T>>, T>(arg_275_0, func4));
						}
						dataContext.SubmitChanges(1);
					}
					catch (Exception ex)
					{
						Log.smethod_1("storage", "StorageTable updateList exception" + ex);
						this.clearException(dataContext);
						this.debugBreak();
						return false;
					}
				}
				return true;
			}
			return false;
		}
		public bool dataChangeResponse(List<DataChange> changeList)
		{
			if (changeList != null && Enumerable.Count<DataChange>(changeList) > 0 && this.isReady())
			{
				DebugEx.getTimeSpan();
				Enumerable.Count<DataChange>(changeList);
				using (DataContext dataContext = this.mapping.newDB())
				{
					Table<T> table = dataContext.GetTable<T>();
					try
					{
						using (List<DataChange>.Enumerator enumerator = changeList.GetEnumerator())
						{
							while (enumerator.MoveNext())
							{
								DataChange current = enumerator.get_Current();
								T t = current.data as T;
								if (t != null)
								{
									switch (current.dataOper_0)
									{
									case DataOper.const_0:
										table.InsertOnSubmit(t);
										break;
									case DataOper.const_1:
										table.Attach(t);
										dataContext.Refresh(0, t);
										table.DeleteOnSubmit(t);
										break;
									case DataOper.modify:
										table.Attach(t);
										dataContext.Refresh(0, t);
										break;
									}
								}
							}
						}
						dataContext.SubmitChanges(1);
						return true;
					}
					catch (Exception ex)
					{
						this.clearException(dataContext);
						Log.smethod_1("storage", "StorageTable  doDataChage exception" + ex);
						this.debugBreak();
					}
				}
				return true;
			}
			return false;
		}
		public bool dataChangeRequest(DataOper dataOper_0, T data)
		{
			if (this.isReady() && this.getKey != null)
			{
				if (this.storageSynchro_0 == null)
				{
					this.storageSynchro_0 = new StorageSynchro<T, PKey>(this, this.getKey);
					StorageBasic.registerFlushNotify(this);
				}
				this.storageSynchro_0.method_0(dataOper_0, data.clone<T>());
				return true;
			}
			return false;
		}
		public void onFlush()
		{
			if (this.bInit && this.storageSynchro_0 != null)
			{
				this.storageSynchro_0.doSaveChange();
				Log.smethod_5("storage", "flush  end " + typeof(T).get_Name());
				return;
			}
		}
		public int setFlushCompleteHandler(Action Flushcomplete)
		{
			if (this.storageSynchro_0 == null)
			{
				this.storageSynchro_0 = new StorageSynchro<T, PKey>(this, this.getKey);
				StorageBasic.registerFlushNotify(this);
			}
			return this.storageSynchro_0.setFlushCompleteHandler(Flushcomplete);
		}
		public virtual void notify(int operation, T item)
		{
		}
		public virtual void dumpTableName()
		{
			using (DataContext dataContext = this.mapping.newDB())
			{
				dataContext.set_ObjectTrackingEnabled(false);
				IEnumerable<MetaTable> enumerable = Enumerable.Select<MetaTable, MetaTable>(dataContext.get_Mapping().GetTables(), (MetaTable metaTable_0) => metaTable_0);
				using (IEnumerator<MetaTable> enumerator = enumerable.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						MetaTable current = enumerator.get_Current();
						using (IEnumerator<MetaDataMember> enumerator2 = current.get_RowType().get_DataMembers().GetEnumerator())
						{
							while (enumerator2.MoveNext())
							{
								MetaDataMember current2 = enumerator2.get_Current();
								Log.smethod_1("storage", string.Format("\t{0}\t{1}", current2.get_MappedName(), current2.get_DbType()));
							}
						}
					}
				}
			}
		}
		public virtual void dumpTable()
		{
			if (!this.bInit)
			{
				return;
			}
			using (DataContext dataContext = this.mapping.newDB())
			{
				dataContext.set_ObjectTrackingEnabled(false);
				Table<T> table = dataContext.GetTable<T>();
				IQueryable<T> queryable = Queryable.Select<T, T>(table, (T m) => m);
				if (Queryable.Count<T>(queryable) > 0)
				{
					int num = 0;
					using (IEnumerator<T> enumerator = queryable.GetEnumerator())
					{
						while (enumerator.MoveNext())
						{
							T arg_74_0 = enumerator.get_Current();
							num++;
						}
					}
				}
			}
		}
	}
}
